package com.example.demo.controller;

import com.example.demo.entity.User;
import com.example.demo.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>Description:</p>
 * <p>Copyright: Copyright (c) 2017</p>
 *
 * @author gaol
 * @version 1.0
 * @date 2017/6/5
 */
@RestController
@RequestMapping(value = "/user")
public class UserController {

    /**
     *
     */
    @Autowired
    private UserMapper userMapper;


    @GetMapping(value = "/{id}")
    public User getUser(@PathVariable("id") Long id) {
        return userMapper.select(id);
    }

    @PostMapping(value = "/add")
    public int addUser(String name, String password) {
        User user = new User();
        user.setPassword(password);
        user.setName(name);
        return userMapper.insert(user);
    }

    @PutMapping(value = "/update")
    public int update(String name){
        User user = new User();
        user.setName(name);
        user.setPassword("654321");
        return userMapper.update(user);
    }

    @PostMapping(value = "/delete")
    public int delete(Long id){
        return userMapper.delete(id);
    }

}
